using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestAjaxWithASP
{
	/// <summary>
	/// Summary description for DatagridEx.
	/// </summary>
	public partial class DatagridEx : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DropDownList ddlcity;
		protected System.Web.UI.WebControls.DataGrid dgauthors;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				//Add client script attribute to the dropdownlist
				ddlcity.Attributes.Add("onchange", "FetchDGContents()");

				// Fill all the cities from the authors table
				FillCity();
				// Fill the datagrid with Top 1 row
				FillGrid();
			}
		}

		private void FillCity()
		{
			System.Data.OleDb.OleDbConnection con =
				new System.Data.OleDb.OleDbConnection();
			con.ConnectionString=@"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Data Source=""D:\Documents and Settings\Mina\My Documents\DBTest.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
			System.Data.OleDb.OleDbDataAdapter DA = new System.Data.OleDb.OleDbDataAdapter
				("select * from Customers", con);
			DataTable dt = new DataTable();
			DA.Fill(dt);
			ddlcity.DataTextField = "CustName";
			ddlcity.DataValueField = "CustID";
			ddlcity.DataSource = dt;
			ddlcity.DataBind();
			ddlcity.Items.Add("All Cities");
			ddlcity.SelectedIndex = ddlcity.Items.Count - 1;
		}

		private void FillGrid()
		{
			System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection();
			con.ConnectionString=@"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Data Source=""D:\Documents and Settings\Mina\My Documents\DBTest.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
			System.Data.OleDb.OleDbDataAdapter DA =new System.Data.OleDb.OleDbDataAdapter
				("select * from Sales", con);
			DataTable dt = new DataTable();
			DA.Fill(dt);
			dgauthors.DataSource = dt;
			dgauthors.DataBind();
		}
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
